require(['./config'], () => {
    require(['header', 'footer', 'util'], () => {
        class Register {
            constructor() {
                this.reg()
            }
            reg() {
                $('#regBtn').on('click', () => {
                    this.username = $('#username').val()
                    this.password = $('#password').val()
                    this.userList = localStorage.getItem('userList')

                    // 判断localStorage里是否已经有数据,如果有，执行下面的代码
                    if (this.userList) {
                        this.userList = JSON.parse(this.userList)
                        console.log(this.userList)

                        // 把当前这次的用户信息push到数组里，然后重新存localStorage
                        this.userList.push({ username: this.username, password: this.password })
                        localStorage.setItem('userList', JSON.stringify(this.userList))

                    } else {
                        // 第一次存
                        this.userinfo = { username: this.username, password: this.password }
                        // 为后面存储更加方便，所以第一次就存一个只有一个元素的数组
                        this.arr = [this.userinfo]
                        localStorage.setItem('userList', JSON.stringify(this.arr))
                    }
                    alert('注册成功，即将跳转登录页面')
                    window.location.href = '/html/login.html'

                })
            }
        }
        new Register()
    })
})